/**
 * 
 */
package Database;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.tomcat.dbcp.dbcp.BasicDataSource;


/**
 * @author yunxue
 *
 */
public class DataBaseConnectionPool {
	
	public static Connection getDBConnection() throws NamingException, SQLException {
		Context initContext = new InitialContext();
	    Context envContext  = (Context)initContext.lookup("java:/comp/env");
	    BasicDataSource ds = (BasicDataSource)envContext.lookup("jdbc/vlmsDS");
	    
	    ds.setDriverClassName("com.mysql.jdbc.Driver");
	    ds.setUrl("jdbc:mysql://localhost:3306/test");
	    ds.setUsername("mshen");

	    Connection conn = ds.getConnection();
	    
		if (!conn.isClosed())
			System.out.println("Successfully Connected!");
		return conn;
	}
	
	
}
